/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.huyu.substat.modules.substat.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.huyu.substat.modules.substat.entity.TbTeacherFulltime;
import com.huyu.substat.modules.substat.service.TbTeacherFulltimeService;

/**
 * 项目人才获奖情况Controller
 * @author huyu
 * @version 2017-01-06
 */
@Controller
@RequestMapping(value = "${adminPath}/substat/tbTeacherFulltime")
public class TbTeacherFulltimeController extends BaseController {

	@Autowired
	private TbTeacherFulltimeService tbTeacherFulltimeService;
	
	@ModelAttribute
	public TbTeacherFulltime get(@RequestParam(required=false) String id) {
		TbTeacherFulltime entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbTeacherFulltimeService.get(id);
		}
		if (entity == null){
			entity = new TbTeacherFulltime();
		}
		return entity;
	}
	
	@RequiresPermissions("substat:tbTeacherFulltime:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbTeacherFulltime tbTeacherFulltime, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbTeacherFulltime> page = tbTeacherFulltimeService.findPage(new Page<TbTeacherFulltime>(request, response), tbTeacherFulltime); 
		model.addAttribute("page", page);
		return "modules/substat/tbTeacherFulltimeList";
	}

	@RequiresPermissions("substat:tbTeacherFulltime:view")
	@RequestMapping(value = "form")
	public String form(TbTeacherFulltime tbTeacherFulltime, Model model) {
		model.addAttribute("tbTeacherFulltime", tbTeacherFulltime);
		return "modules/substat/tbTeacherFulltimeForm";
	}

	@RequiresPermissions("substat:tbTeacherFulltime:edit")
	@RequestMapping(value = "save")
	public String save(TbTeacherFulltime tbTeacherFulltime, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbTeacherFulltime)){
			return form(tbTeacherFulltime, model);
		}
		tbTeacherFulltimeService.save(tbTeacherFulltime);
		addMessage(redirectAttributes, "保存项目人才获奖情况成功");
		return "redirect:"+Global.getAdminPath()+"/substat/tbTeacherFulltime/?repage";
	}
	
	@RequiresPermissions("substat:tbTeacherFulltime:edit")
	@RequestMapping(value = "delete")
	public String delete(TbTeacherFulltime tbTeacherFulltime, RedirectAttributes redirectAttributes) {
		tbTeacherFulltimeService.delete(tbTeacherFulltime);
		addMessage(redirectAttributes, "删除项目人才获奖情况成功");
		return "redirect:"+Global.getAdminPath()+"/substat/tbTeacherFulltime/?repage";
	}

}